package com.cvnert.testplatform.controller;

import com.cvnert.testplatform.config.AliOSSUtils;
import com.cvnert.testplatform.utils.ResultJson;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@CrossOrigin(origins = "*")
@RequestMapping("/upload")
@RestController
public class FileUploadController {
    @Resource
    private AliOSSUtils aliOSSUtils;

    @PostMapping("/upload")
    public ResultJson<String> upload(MultipartFile file) throws IOException {
        //调用阿里云OSS工具类进行文件上传
        String url = aliOSSUtils.upload(file);
        return ResultJson.success(url);
    }
}
